package com.sf.fy.uav.controller;

import com.sf.fy.uav.common.awt.JwtUtil;
import com.sf.fy.uav.common.request.operate.RecordModuleDurationRequest;
import com.sf.fy.uav.common.utils.BeanUtil;
import com.sf.fy.uav.entity.RecordModuleDuration;
import com.sf.fy.uav.mapper.RecordModuleDurationMapper;
import com.sf.fy.uav.service.IRecordModuleDurationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author LTQ
 * @since 2023-11-23
 */
@RestController
public class RecordModuleDurationRest {

    @Autowired
    private RecordModuleDurationMapper recordModuleDurationMapper;

    @Autowired
    private IRecordModuleDurationService iRecordModuleDurationService;

    public void add(@RequestBody RecordModuleDurationRequest recordModuleDurationRequest) {
        String userId = recordModuleDurationRequest.getUserId();
        if (ObjectUtils.isEmpty(userId)) {
            userId = JwtUtil.getUserId();
        }
        Date date = new Date();
        RecordModuleDuration recordModuleDuration = BeanUtil.copyProperties(recordModuleDurationRequest, RecordModuleDuration.class);
        recordModuleDuration.setCreateTime(date);
        recordModuleDuration.setUserId(userId);
        recordModuleDurationMapper.insert(recordModuleDuration);
    }


    public Long countBySubjectId(String subjectId, String subject) {
        return iRecordModuleDurationService.countBySubjectId(subjectId, subject);
    }

    public RecordModuleDuration selectLastBySubjectId(String subjectId, String subject) {
        return iRecordModuleDurationService.selectLastBySubjectId(subjectId, subject);
    }

    public List<RecordModuleDuration> selectRecordModuleDurationListBySubjectIds(List<String> ids) {
        return iRecordModuleDurationService.selectRecordModuleDurationListBySubjectIds(ids);
    }
}
